#include<iostream>
#include<string>
using namespace std;
const int N = 1e3 + 10;
string s1, s2;
int f[N][N];
int n, m;
int main()
{
	cin >> s1 >> s2;
	s1 = " " + s1;
	s2 = " " + s2;
	n = s1.size() - 1, m = s2.size() - 1;
	int idx = 0, ans = 0;
	//absbsca
	//aesbsck
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s1[i] == s2[j]) {
				f[i][j] = max(f[i - 1][j - 1] + 1, f[i][j]);
				if (f[i][j] >= ans) {
					idx = j;
					ans = f[i][j];
				}
			}
		}
	}
	cout << ans << endl;
	cout << idx << endl;
	for (int i = idx - ans + 1; i <= idx; i++) {
		cout << s2[i];
	}
	return 0;
}
